#定义一个函数
def sayHello():
    print("hello world")

sayHello()

#函数带参数和返回值
def sum(a, b):
    return a + b

print(sum(1, 2))
print(sum(1.1, 2.2))


#函数带默认值
def pow(a, b=2):
    return a ** b

print(pow(2)) #4
print(pow(2,3)) #8
print(pow(b=1, a=2)) #2


#函数返回tuple
def getData(a, b):
    return a,b  #返回tuple (a,b)

print(getData(1,2))

c,d = getData(1,2)
print(c, d)

#函数的参数是可变值
def sortList(list):
    list.sort(key=None,reverse=False)

list = [3,1,2,5]
sortList(list)
print(list) #[1,2,3,5]


#函数作用域 局部变量
print('函数作用域')
a = 1
def testScope1():
    a = 2
    print(a) #2

testScope1()
print(a) #1

#函数作用域 修改全局变量
print('修改全局变量')
b = 1
def testScope2():
    global b
    b = 2
    print(b) #2

testScope2()
print(b) #2